//
//  ByUIAboutVC.m
//  oc_knowledge
//
//  Created by justiOS on 17/1/16.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUIAboutVC.h"

@interface ByUIAboutVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;
// data
@property (nonatomic, strong) NSArray           *subjects;
@property (nonatomic, strong) NSMutableArray    *subjectDetails;


@end

@implementation ByUIAboutVC
- (NSArray *)subjects {
    if (!_subjects) {
        _subjects = @[@"", @"欢迎页", @"新浪微博", @"微信公众号",@"客服电话",@"用户服务协议"];
    }
    return _subjects;
}
- (NSMutableArray *)subjectDetails {
    if (!_subjectDetails) {
//        NSString *tel = [ByNetConfig getCustomerPhone];
        NSArray *temp = @[@"", @"", @"博也科技", @"博也科技",@"0571-88888888",@""];
        _subjectDetails = [[NSMutableArray alloc] initWithArray:temp];
    }
    return _subjectDetails;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"关于我们";
    [self addLeftBackBarButtonItem];
//    [self addBYItemviews:@[@"返回"] mode:ByNavigationItemModeText position:ByNavigationItemPositionModeLeft];
    [self createTableView];
}
- (void)createTableView {
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT -64) style:UITableViewStylePlain];
    self.table.backgroundColor = TABLE_COLOR;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:_table];
    
}


#pragma mark - UITableViewDataSource UITableViewDelegate
// 设置组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
// 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.subjects.count;
}
// 设置单元格属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.textLabel.textColor = [UIColor darkGrayColor];
        cell.textLabel.font = FONT(16);
        cell.detailTextLabel.textColor = [UIColor lightGrayColor];
        cell.detailTextLabel.font = FONT(16);
        cell.detailTextLabel.textColor = rgba(238, 80, 51, 1);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.textLabel.text = self.subjects[indexPath.row];
    cell.detailTextLabel.text = self.subjectDetails[indexPath.row];
    
    
    if (indexPath.row == 1 || indexPath.row == 5) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
    }
    if (indexPath.row == 0) {
        UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 45, 35, 90.5, 90)];
        imgview.layer.cornerRadius = 5;
        imgview.layer.masksToBounds = YES;
//        imgview.image = [UIImage imageNamed:@"mine_app_logo"];
        imgview.image = [UIImage imageWithColor:rgba(238, 80, 51, 1)];
        [cell addSubview:imgview];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, imgview.bottom + 15, SCREEN_WIDTH, 20)];
        
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor darkGrayColor];
        label.text = [NSString stringWithFormat:@"版本号v%@",APP_VERSION];
        [cell addSubview:label];
        
        
        
        cell.backgroundColor = [UIColor clearColor];
        UIView *sep = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
        sep.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1];
        [cell addSubview:sep];
        sep.bottom = 200;
    }else{
        cell.backgroundColor = [UIColor whiteColor];
        if (indexPath.row == 4) {
            UIView *sep = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
            sep.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1];
            [cell addSubview:sep];
            sep.bottom = 44;
        }else{
            UIView *sep = [[UIView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 15, 1)];
            sep.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1];
            [cell addSubview:sep];
            sep.bottom = 44;
        }
    }
    
    return cell;
    
}
// 设置单元格行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 200;
    }
    return 44;
}

// 单元格点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    // 欢迎页
    if (indexPath.row == 1) {
//        ByWelcomeVC *vc = [[ByWelcomeVC alloc] init];
//        [self by_normalPush:vc hasNavi:YES];
        [ByCoreToolAlert showOnlyText:@"跳转欢迎页"];
    }
    if (indexPath.row == 4) {
        NSString *tel = [NSString stringWithFormat:@"tel:%@",_subjectDetails[4]];
        //        NSString *tel = [NSString stringWithFormat:@"tel:400-863-9156"];
        //        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
        UIWebView * Webview = [[UIWebView alloc] init];
        [Webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tel]]];
        [self.view addSubview:Webview];
    }
    if (indexPath.row == 5) {
        NSString *str = [NSString stringWithFormat:@"https://api.ryzcgf.com/public/web.php/web/copyright"];
        ByWebViewController *vc = [[ByWebViewController alloc] initWithTotalUrlString:str];
        vc.title = @"用户服务协议";
        [self by_normalPush:vc hasNavi:YES];
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
